home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Bitmap / Sources / RbbrBand.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.0 KB  |  182 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                RbbrBand.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Bitmap.hpp"
  13.  
  14. #ifndef RBBRBAND_H
  15. #include "RbbrBand.h"
  16. #endif
  17.  
  18. #ifndef FRAME_H
  19. #include "Frame.h"
  20. #endif
  21.  
  22. // ----- Parts Layer -----
  23.  
  24. #ifndef FWUTIL_H
  25. #include "FWUtil.h"
  26. #endif
  27.  
  28. #ifndef FWVIEW_H
  29. #include "FWView.h"
  30. #endif
  31.  
  32. #ifndef FWITERS_H
  33. #include "FWIters.h"
  34. #endif
  35.  
  36. #ifndef FWCONTXT_H
  37. #include "FWContxt.h"
  38. #endif
  39.  
  40. // ----- OS Layer -----
  41.  
  42. #ifndef FWSTYLE_H
  43. #include "FWStyle.h"
  44. #endif
  45.  
  46. #ifndef FWINK_H
  47. #include "FWInk.h"
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Runtime Information
  52. //========================================================================================
  53.  
  54. #ifdef FW_BUILD_MAC
  55. #pragma segment odfbitmap
  56. #endif
  57.  
  58. //========================================================================================
  59. //    class CRectRubberBand
  60. //========================================================================================
  61.  
  62. //-----------------------------------------------------------------------------------------
  63. //    CRectRubberBand::CRectRubberBand
  64. //-----------------------------------------------------------------------------------------
  65.  
  66. CRectRubberBand::CRectRubberBand(Environment* ev, CBitmapFrame* frame, ODFacet* facet, const FW_CRect& maxRect, const FW_CPoint& zoomRatio) :
  67.     FW_CTracker(ev, frame, facet),
  68.     fMaxRect(maxRect),
  69.     fZoomRatio(zoomRatio),
  70.     fRectShape(FW_kZeroRect, FW_kFrame),
  71.     fBitmapFrame(frame)
  72. {
  73.     FW_CInk ink(FW_kRGBBlack, FW_kRGBWhite, FW_kXOr);
  74.     FW_CStyle style(FW_kFixed0, FW_kAntPat);
  75.     
  76.     fRectShape.SetInk(ink);
  77.     fRectShape.SetStyle(style);
  78. }
  79.  
  80. //-----------------------------------------------------------------------------------------
  81. //    CRectRubberBand::~CRectRubberBand
  82. //-----------------------------------------------------------------------------------------
  83.  
  84. CRectRubberBand::~CRectRubberBand()
  85. {
  86. }
  87.  
  88. //-----------------------------------------------------------------------------------------
  89. //    CRectRubberBand::BeginTracking
  90. //-----------------------------------------------------------------------------------------
  91.  
  92. FW_CPoint CRectRubberBand::BeginTracking(Environment* ev, 
  93.                                          const FW_CPoint& anchorPoint)
  94. {
  95.     FW_CPoint curLoc = AlignOnPixel(anchorPoint);
  96.     
  97.     FW_CRect rect(curLoc, curLoc);
  98.     fRectShape.SetRectangle(rect);
  99.     DrawRubberBand(ev);
  100.     
  101.     return curLoc;
  102. }
  103.  
  104. //-----------------------------------------------------------------------------------------
  105. //    CRectRubberBand::ContinueTracking
  106. //-----------------------------------------------------------------------------------------
  107.  
  108. FW_CPoint CRectRubberBand::ContinueTracking(Environment* ev, 
  109.                                             const FW_CPoint& anchorPoint, 
  110.                                             const FW_CPoint& previousPoint, 
  111.                                             const FW_CPoint& currentPoint)
  112. {
  113. FW_UNUSED(previousPoint);
  114.     FW_CPoint curLoc = AlignOnPixel(currentPoint);
  115.  
  116.     FW_CRect rect(anchorPoint, curLoc);
  117.     rect.Sort();
  118.     rect.Intersection(fMaxRect);
  119.     
  120.     FW_CRect shapeBounds;
  121.     fRectShape.GetRectangle(shapeBounds);
  122.     if (rect != shapeBounds)
  123.     {
  124.         DrawRubberBand(ev);        // erase
  125.         fRectShape.SetRectangle(rect);
  126.         DrawRubberBand(ev);        // draw
  127.     }
  128.     
  129.     return currentPoint;
  130. }
  131.  
  132. //-----------------------------------------------------------------------------------------
  133. //    CRectRubberBand::DrawRubberBand
  134. //-----------------------------------------------------------------------------------------
  135. // I want to draw the rubberband in every facet
  136.  
  137. void CRectRubberBand::DrawRubberBand(Environment* ev)
  138. {
  139.     FW_CFrameFacetIterator ite(ev, fBitmapFrame);
  140.     for (ODFacet* aFacet = ite.First(ev); ite.IsNotComplete(ev); aFacet = ite.Next(ev))
  141.     {
  142.         FW_CViewContext vc(ev, fBitmapFrame, aFacet);
  143.         fRectShape.Render(vc);        
  144.     }
  145. }
  146.  
  147. //-----------------------------------------------------------------------------------------
  148. //    CRectRubberBand::EndTracking
  149. //-----------------------------------------------------------------------------------------
  150.  
  151. FW_Boolean CRectRubberBand::EndTracking(Environment* ev, 
  152.                                     const FW_CPoint& anchorPoint, 
  153.                                     const FW_CPoint& lastPoint)
  154. {
  155.     DrawRubberBand(ev);    // erase
  156.     
  157.     return anchorPoint != lastPoint;
  158. }
  159.  
  160. //-----------------------------------------------------------------------------------------
  161. //    CRectRubberBand::AlignOnPixel
  162. //-----------------------------------------------------------------------------------------
  163. //    We want, what ever the zoom factor, always have the selection rectangle on a pixel boundary
  164.  
  165. FW_CPoint CRectRubberBand::AlignOnPixel(const FW_CPoint& location)
  166. {
  167.     FW_CPoint result = location - fMaxRect[FW_kTopLeft];
  168.         
  169.     result.x = result.x / fZoomRatio.x;
  170.     result.y = result.y / fZoomRatio.y;
  171.     
  172.     result.x = FW_RoundedToInt(result.x);
  173.     result.y = FW_RoundedToInt(result.y);
  174.  
  175.     result.x *= fZoomRatio.x;
  176.     result.y *= fZoomRatio.y;
  177.         
  178.     result += fMaxRect[FW_kTopLeft];
  179.     
  180.     return result;
  181. }
  182.